import fs from "node:fs";
import path from "node:path";
const dir = path.resolve(__dirname, "../projects");
const listJsonPath = path.resolve(
  __dirname,
  "../server/constants/projectList.json"
);
const typePath = path.resolve(
  __dirname,
  "../server/src/model/BuildTaskType.ts"
);
const data = fs.readdirSync(dir);

// 生成支持的类型列表
const typeList = data.map((v) => {
  const tag = v.includes("element-plus") ? "WithElementPlus" : "Basic";
  const name = (v.charAt(0).toUpperCase() + v.slice(1)).replace(/-/g, " ");
  return {
    tag,
    type: v,
    name,
  };
});

fs.writeFileSync(
  typePath,
  `export type BuildTaskType = ${data.map((v) => `\"${v}\"`).join(" | ")};`
);
fs.writeFileSync(listJsonPath, JSON.stringify(typeList, null, 2));

console.log('...init type list success...')
// console.log(
//   "type list",
//   typeList.map((v) => v.type)
// );
